#include <all.h>


extern u8 uart_buffer[72];

void delay(u16 x)
{
	while(x--);
}

void write_seg(u8 dat)
{
	u8 i;
	for(i=0;i<8;i++)
	{
		if((dat&0x80))
			seg_dat=1;
		else
			seg_dat=0;
		seg_clk=0;
		dat<<=1;
		seg_clk=1;
	}
}
void com_start()
{
	com_dat=0;
	com_clk=0;
	com_clk=1;
	com_dat=1;	
}
void com_crol()
{
	com_clk=0;
	com_clk=1;
}

void hc595_to_led()
{
	rck=0;
	rck=1;
}


void hc595_init()
{
	u8 i;
	com_dat=1;
	for(i=0;i<46;i++)
	{
		com_clk=0;
		com_clk=1;
	}
	hc595_to_led();
}

	u8 i,j;
	u8 cont;
	u16 x;


void write_ui()
{
	short flg;
	cont=3;
	com_start();
	for(i=0;i<23;i++)
	{
		
		for(j=0;j<2;j++)
		{
			if(j)
			{
				x=uart_buffer[cont+2]<<1;	
			}
			else
			{
				x=uart_buffer[cont+1]<<1;
			}
			if(x)
				write_seg(uart_buffer[cont]);
			else
				write_seg(0);
	
			hc595_to_led();
			com_crol();
			delay(x);
			write_seg(0x00);
			hc595_to_led();
			delay(511-x);	
		}
		cont+=3;
	}
	hc595_to_led();
	flg=0-uart_buffer[72];
	flg+=255;
	flg<<=3;
	delayus(flg);
}













